<script setup lang="ts">
import { computed, useSlots } from 'vue'

const hasSearch = computed(() => useSlots().search)
const searchHeight = computed(() => {
  if (!hasSearch.value)
    return '0px'
  const dom = document.getElementById('page-search') as any
  return `${dom?.offsetHeight}px`
})
</script>

<template>
  <a-layout class="page-layout">
    <a-layout-header class="gp__flex-between" :class="{ 'header-shadow': !hasSearch }">
      <GpBreadcrumb />
      <div><slot name="operate" /></div>
    </a-layout-header>
    <a-layout-content>
      <div id="page-search" :class="{ 'page-search': hasSearch }">
        <slot name="search" />
      </div>
      <div class="page-content" :class="{ 'no-search': !hasSearch }">
        <slot name="content" />
      </div>
    </a-layout-content>
  </a-layout>
</template>

<style lang="less" scoped>
.page-layout {
  border-top-right-radius: 5px;
  ::v-deep(.ant-layout-header) {
    height: 62px;
    line-height: 62px;
    padding: 0 20px;
    background: @color-page-header;
    font-size: @font-size-medium-x;
    font-family: Web_SemiBold;
    z-index: 9;
    margin: 0 !important;
    &.header-shadow {
      box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    }
  }
  .ant-layout-content {
    position: relative;
    background-color: @color-background;
  }

  .page-content {
    height: calc(100vh - 205px - v-bind(searchHeight));
    overflow-y: auto;
    padding: 15px 15px;
    &.no-search {
      height: calc(100vh - 205px);
    }
  }

  .page-search {
    padding: 20px 20px 0;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid #dfdfdf;
  }
}
</style>
